const Controller = require("egg").Controller;

let sockets = {};
class Test extends Controller {
  async msg() {
    const { ctx, app } = this;
    const message = ctx.args[0] || {};
    const nsp = app.io.of("/");
    const socket = ctx.socket;
    const { id } = socket.handshake.query;

    nsp.clients((err, client) => {
      console.log("==", client);
    });

    if (id) {
      sockets[id] = socket;
      // sockets[id].emit("msg", "]]]]");
      // sockets[id].emit("2000", "]]]]");
    }
    try {
      const { id, msg } = message;
      if (!id) return;
      // const msg = ctx.helper.parseMsg('exchange', payload, { client, target });
      sockets[id].emit("recive", msg);
    } catch (error) {}
  }
}

module.exports = Test;
